#include<bits/stdc++.h>
using namespace std;

struct Student
{
	string name;
	int month, day;
}stu[200];

bool cmp(Student x, Student y)
{
	if(x.month != y.month)
		return x.month < y.month;
	else if(x.day != y.day)
		return x.day < y.day;
	else if(x.name.size() != y.name.size())
		return x.name.size() < y.name.size();
	else
		return x.name < y.name;
}

int main()
{
	int n;
	cin>>n;
	for(int i = 1;i <= n;i++)
		cin>>stu[i].name>>stu[i].month>>stu[i].day;
	sort(stu+1, stu+n+1, cmp);
	int flag = 0;
	for(int i = 1;i <= n;i++)
		for(int j = i+1;j <= n;j++)
			if(stu[i].month == stu[j].month && stu[i].day == stu[j].day)
				flag = 1;
	if(flag)
	{
		for(int i = 1;i <= n;i++)
		{
			flag = i;
			int m = stu[i].month, d = stu[i].day;
			for(int j = i+1;j <= n;j++)
			{
				if(stu[j].month == m && stu[j].day == d)
					flag = j;
				else
					break;
			}
			if(flag == i)
				continue;
			cout<<m<<" "<<d<<" ";
			for(int j = i;j <= flag;j++)
				cout<<stu[j].name<<" ";
			cout<<endl;
			i = flag;
		}
	}
	else
		cout<<"None";
    return 0;
}

